package com.hanxiaozhang.system.dao;

import com.hanxiaozhang.system.dto.MenuDTO;
import com.hanxiaozhang.system.entity.MenuEntity;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

/**
 * 菜单表
 *
 * @author hanxiaozhang
 * @email hanxiaozhang2018@sina.com
 * @date 2020-10-14
 */
@Mapper
public interface MenuDao {

	MenuEntity get(Long menuId);

	List<MenuDTO> list(Map<String,Object> map);

	int save(MenuEntity menu);

	int update(MenuEntity menu);

	int remove(Long menuId);

	int batchRemove(Long[] menuIds);


	/**
	 * 更新子部门个数通过id
	 *
	 * @param menuId
	 * @param num
	 * @return
	 */
	@Update("UPDATE sys_menu SET sub_count = IFNULL(sub_count,0) + (#{num}) WHERE menu_id =#{menuId} AND del_flag = 0")
	int updateSubCountById(@Param("menuId") Long menuId, @Param("num") Integer num);



	/**
	 * 通过用户id获取菜单
	 *
	 * @param userId
	 * @return
	 */
	List<MenuEntity> listMenuByUserId(@Param("userId") Long userId);

	/**
	 * 通过用户id获取权限
	 *
	 * @param userId
	 * @return
	 */
	List<String> listPermsByUserId(@Param("userId") Long userId);
	
}
